package com.qf.business.message.handler.base;

import com.qf.business.message.entity.Message;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * author Ken
 * create_time 2023/1/6
 */
public abstract class BaseMsgChannelHandler extends SimpleChannelInboundHandler<Message> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
        if (msg.getAction().equals(action())) {
            handler(ctx, msg);
        } else {
            ctx.fireChannelRead(msg);
        }
    }

    protected abstract String action();

    protected abstract void handler(ChannelHandlerContext ctx, Message msg);
}
